#region Usings

using System;
using Newtonsoft.Json;
using Karma.Framework.Core.Domain;

#endregion

namespace Karma.Framework.Core.Serialization.Json.Converters
{
    public class DomainObjectConverter<T> : JsonConverter where T : DomainObject
    {
        public override bool CanConvert(Type objectType)
        {
            return typeof (T).IsAssignableFrom(objectType);
        }

        public override object ReadJson(JsonReader reader, Type objectType)
        {
            throw new InvalidOperationException();
        }

        public override void WriteJson(JsonWriter writer, object value)
        {
            var e = (T) value;
            //writer.WriteValue(e.ToString());
            writer.WriteValue(Convert.ToInt32(e));
        }
    }
}